package com.luckymore.ydd.app.util;

import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.base.control.ActionBarControl;
import com.base.control.MActivitySupport;
import com.base.view.holder.ActionBarCommons;
import com.luckymore.ydd.app.R;
import com.luckymore.ydd.app.view.holder.ActionBarTabBtn;

/**
 * Created by yjh on 15-3-10.
 */
public class ActionBarSubControl {

    /**
     * 左button 中title 有button布局的actionbar
     */
    public static ActionBarCommons setActionBarCommons(MActivitySupport act) {
        ActionBarCommons actionBarCommons = null;

        View actionbarView = ActionBarControl.setActionBar(act, R.layout.actionbar_commons);

        if(actionbarView != null) {
            actionBarCommons = new ActionBarCommons();
            actionBarCommons.setLeftBtn((Button)actionbarView.findViewById(R.id.left_btn));
            actionBarCommons.setTitleTv((TextView)actionbarView.findViewById(R.id.head_title));
            actionBarCommons.setRightBtn((Button)actionbarView.findViewById(R.id.head_right_btn));
            actionBarCommons.setContentView(actionbarView);
            act.setBackBtn(actionBarCommons.getLeftBtn()); //设置该activity的返回按钮
            act.setTitleTv(actionBarCommons.getTitleTv());
        }

        return actionBarCommons;
    }

    public static ActionBarCommons setHeaderBarCommons(MActivitySupport act, ViewGroup header) {
        ActionBarCommons actionBarCommons = null;

        View actionbarView = ActionBarControl.setHeaderBar(act, header, R.layout.actionbar_commons);

        if(actionbarView != null) {
            actionBarCommons = new ActionBarCommons();
            actionBarCommons.setLeftBtn((Button)actionbarView.findViewById(R.id.left_btn));
            actionBarCommons.setTitleTv((TextView)actionbarView.findViewById(R.id.head_title));
            actionBarCommons.setRightBtn((Button)actionbarView.findViewById(R.id.head_right_btn));
            actionBarCommons.setContentView(actionbarView);
            act.setBackBtn(actionBarCommons.getLeftBtn()); //设置该activity的返回按钮
            act.setTitleTv(actionBarCommons.getTitleTv());
        }

        return actionBarCommons;
    }

    public static ActionBarTabBtn setActionBarTabBtn(MActivitySupport act) {
        ActionBarTabBtn actionBarTabBtn = null;

        View actionbarView = ActionBarControl.setActionBar(act, R.layout.actionbar_tab_btn);

        if(actionbarView != null) {
            actionBarTabBtn = new ActionBarTabBtn();
            actionBarTabBtn.setLeftBtn((Button)actionbarView.findViewById(R.id.actionbartb_left_btn));
            actionBarTabBtn.setRadioGroup((RadioGroup) actionbarView.findViewById(R.id.tab_btns));
            actionBarTabBtn.setRightBtn((Button)actionbarView.findViewById(R.id.actionbartb_right_btn));
            act.setBackBtn(actionBarTabBtn.getLeftBtn()); //设置该activity的返回按钮
        }

        return actionBarTabBtn;
    }
}
